package com.freewater.javabase.demo.init.loadandinit;

import java.util.Arrays;

public class SingletonDemoTest {
    public static void main(String[] args) {
        load(); // 只加载SingletonDemo类的Class对象，不会执行初始化SingletonDemo.instance
        //loadAndCall(); // 调用SingletonDemo类的getInstance方法，就会执行初始化SingletonDemo.instance
    }

    public static void load() {
        final Class<SingletonDemo> singletonDemoClass = SingletonDemo.class;
        System.out.println(singletonDemoClass);
        Arrays.stream(singletonDemoClass.getMethods()).forEach(method -> {
            System.out.println(method.getName());
        });
    }

    public static void loadAndCall() {
        System.out.println(SingletonDemo.getInstance().getNumber());
    }
}
